package com.ruoyi.web.controller.file;

import java.util.List;

import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.file.domain.FileConf;
import com.ruoyi.file.service.IFileConfService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件信息配置Controller
 * 
 * @author shushuang
 * @date 2019-11-27
 */
@Controller
@RequestMapping("/file/fileconf")
public class FileConfController extends BaseController
{
    private String prefix = "file/fileconf";

    @Autowired
    private IFileConfService fileConfService;

    @Autowired
    private ISysDictDataService dictDataService;

    @RequiresPermissions("file:fileconf:view")
    @GetMapping()
    public String fileconf()
    {
        return prefix + "/fileconf";
    }

    /**
     * 查询文件信息配置列表
     */
    @RequiresPermissions("file:fileconf:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FileConf fileConf)
    {
        startPage();
        List<FileConf> list = fileConfService.selectFileConfList(fileConf);
        return getDataTable(list);
    }

    /**
     * 导出文件信息配置列表
     */
    @RequiresPermissions("file:fileconf:export")
    @Log(title = "文件信息配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FileConf fileConf)
    {
        List<FileConf> list = fileConfService.selectFileConfList(fileConf);
        ExcelUtil<FileConf> util = new ExcelUtil<FileConf>(FileConf.class);
        return util.exportExcel(list, "fileconf");
    }

    /**
     * 新增文件信息配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文件信息配置
     */
    @RequiresPermissions("file:fileconf:add")
    @Log(title = "文件信息配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FileConf fileConf)
    {
        return toAjax(fileConfService.insertFileConf(fileConf));
    }

    /**
     * 修改文件信息配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FileConf fileConf = fileConfService.selectFileConfById(id);
        mmap.put("fileConf", fileConf);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件信息配置
     */
    @RequiresPermissions("file:fileconf:edit")
    @Log(title = "文件信息配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FileConf fileConf)
    {
        return toAjax(fileConfService.updateFileConf(fileConf));
    }

    /**
     * 删除文件信息配置
     */
    @RequiresPermissions("file:fileconf:remove")
    @Log(title = "文件信息配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fileConfService.deleteFileConfByIds(ids));
    }

    @RequiresPermissions("file:fileconf:edit")
    @PostMapping("/changeEnable")
    @ResponseBody
    public AjaxResult changeEnable(FileConf fileConf)
    {
        return toAjax(fileConfService.changeEnable(fileConf));
    }
}
